﻿using Microsoft.AspNetCore.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Identity;

namespace Wy.JiZhangSoft.Users
{
    public class UserAppService : JiZhangSoftAppService
    {
        private readonly IdentityUserManager _userManager;

        public UserAppService(IdentityUserManager userManager)
        {
            this._userManager = userManager;
        }

        static Random r = new Random();

        public async Task Register(string userName, string password)
        {
            var user = new Volo.Abp.Identity.IdentityUser(GuidGenerator.Create(), userName, "1071+"+ r.Next()+ "@qq.com");
            var result = await _userManager.CreateAsync(user);
            if (!result.Succeeded)
                throw new BusinessException("注册失败");
            result = await _userManager.AddPasswordAsync(user, password);
            if (!result.Succeeded)
                throw new BusinessException("注册失败");
        }
    }
}
